package com.version1.diabeco.ui.comida;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.version1.diabeco.ActivityMain;
import com.version1.diabeco.R;
import com.version1.diabeco.model.comida.Comida;

public class ComidaAdapter extends ArrayAdapter<Comida> {
	private final Context context;
	private final List<Comida> values;

	public ComidaAdapter(Context context, List<Comida> values) {
		super(context, R.layout.activity_comida_fila, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.activity_comida_fila, parent, false);

		Comida comida = values.get(position);

		TextView textView = (TextView) rowView.findViewById(R.id.textViewFilaComidaCuando);
		textView.setText(comida.getCuando());

		textView = (TextView) rowView.findViewById(R.id.textViewFilaAlimentosDistintos);
		textView.setText(String.valueOf(comida.getDetalleComida().size()));

		textView = (TextView) rowView.findViewById(R.id.textViewFilaComidaTotalHdC);
		textView.setText(String.valueOf(comida.getTotalHdC()));

		textView = (TextView) rowView.findViewById(R.id.textViewFilaComidaFecha);
		textView.setText(ActivityMain.DATE_FORMAT.format(comida.getFecha()));

		textView = (TextView) rowView.findViewById(R.id.textViewFilaComidaHora);
		textView.setText(ActivityMain.TIME_FORMAT.format(comida.getFecha()));

		return rowView;
	}
}